﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLayer;
using System.Data;

namespace BusinessLayer
{
    public class News
    {
        public string News_id { get; set; }
        public string News_description { get; set; }

        public News()
        {
            News_id = "";
            News_description = "";

        }

        public News(string news_i, string news_d)
        {
            News_id = news_i;
            News_description = news_d;
        }

        public List<News> get_News()
        {
            List<csparameterListType> par = new List<csparameterListType>();
            List<News> objlist = new List<News>();
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            IDataReader datareader = null;

            datareader = objdal.executespreturndr("Get_News");
            while (datareader.Read())
            {
                News objP = new News();
                populate_reader(datareader, objP);
                objlist.Add(objP);
            }
            return objlist;
        }

       

        private void populate_reader(IDataReader datareader, News objP)
        {
            objP.News_id = datareader.GetString(0);
            objP.News_description = datareader.GetString(1);
        }

        public void add_News()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@News_id",SqlDbType.VarChar , News_id));
            par.Add(new csparameterListType("@News_description", SqlDbType.VarChar, News_description));
            objdal.executespreturnnd("Add_News", par);
        }

        public void delete_News()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@News_id", SqlDbType.VarChar, News_id));

            objdal.executespreturnnd("Delete_News", par);
        }

        public void save_News()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@News_id", SqlDbType.VarChar, News_id));
            par.Add(new csparameterListType("@News_description", SqlDbType.VarChar, News_description));
            objdal.executespreturnnd("Save_News", par);
        }


        }
}